package com.mach.platform.controller;

import com.mach.platform.domain.EnergyStruc;
import com.mach.platform.domain.Response;
import com.mach.platform.service.EnergyStrucServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 * @Description:
 * @Package: com.mach.platform.controller
 * @time 2018/10/19 0019 14:39
 */
@RequestMapping("ens")
@RestController
public class EnergyStrucCtrl extends BaseCtrl<EnergyStruc> {

    @Autowired
    private EnergyStrucServiceImpl energyStrucService;

    /**
     * -- @GetMapping(value = "/info/{id}")
     * -- @ApiOperation(value = "单个实体信息", notes = "接口备注：无", produces = "application/json")
     * 单个数据 的接口
     * -- @PathVariable(value = "id", required = true) Long id
     *
     * @param id 数据的id
     * @return Response
     */
    @Override
    public Response info(Long id) {
        return null;
    }

    /**
     * --	@ApiOperation(value = "列表--分页", produces = "application/json", notes = "列表参数：size(每页数量),page(页码),searchParam(查询内容)")
     * -- @GetMapping(value = "/list")
     * 获取列表数据
     * -- @PageableDefault(size = 25) Pageable pageable
     * -- @RequestParam Map params
     *
     * @param pageable 分页参数
     * @param params   其他参数
     * @return Response
     */
    @GetMapping(value = "/list")
    @Override
    public Response list(@PageableDefault(size = 25) Pageable pageable, Map params) {

        Page<EnergyStruc> result = energyStrucService.list(pageable, params);
        return Response.ok(result);
    }

    /**
     * -- @DeleteMapping("/del")
     * -- @ApiOperation(value = "删除", notes = "接口备注：无", produces = "application/json")
     * 删除数据
     * -- @RequestBody Long[] ids
     *
     * @param ids id的集合
     * @return Response
     */
    @DeleteMapping("/del")
    @Override
    public Response delete(@RequestBody Long[] ids) {

        int delete = energyStrucService.delete(ids);
        return Response.ok(delete);
    }

    /**
     * --@PostMapping("/save")
     * --	@ApiOperation(value = "保存", notes = "接口备注：无", produces = "application/json")
     * 保存一个 对象
     * --@RequestBody T t
     *
     * @param energyStruc 保存的实体
     * @return Response
     */
    @PostMapping("/save")
    @Override
    public Response save(@RequestBody EnergyStruc energyStruc) {
        EnergyStruc energyStruc1 = energyStrucService.save(energyStruc);
        return Response.ok(energyStruc1);
    }

    /**
     * --@PutMapping("/upd")
     * --	@ApiOperation(value = "更新", notes = "接口备注：无", produces = "application/json")
     * 更新一个对象
     * --@RequestBody T t
     *
     * @param energyStruc 更新的实体
     * @return Response
     */
    @PutMapping("/upd")
    @Override
    public Response update(@RequestBody EnergyStruc energyStruc) {
        EnergyStruc energyStruc1 = energyStrucService.update(energyStruc);
        return Response.ok(energyStruc1);
    }

    /**
     * 获取 树 数据
     *
     * @param factory
     * @param type
     * @return
     */
    @PostMapping("tree")
    public Response tree(@RequestParam("factory") String factory, @RequestParam("type") String type) {

        List<EnergyStruc> treeDatas = energyStrucService.getTreeDatas(factory, type);

        return Response.ok(treeDatas);
    }

    @ApiOperation(value = "加载EMS空间选择架构", notes = "接口备注：无", produces = "application/json")
    @PostMapping("ecss")
    public Response loadDefaultEnergyStucts(@RequestParam("type") String type) {
        List<EnergyStruc> treeDatas = energyStrucService.loadModelSpaceDatas(type);
        return Response.ok(treeDatas);
    }

    @ApiOperation(value = "加载EMS空间菜单", notes = "接口备注：无", produces = "application/json")
    @PostMapping("menus")
    public Response loadEnergyStuctsMenus(@RequestParam("spaces") String spaces) {

        List<Map> treeDatas = energyStrucService.loadEnergyStuctsMenus(spaces);
        return Response.ok(treeDatas);
    }

    @ApiOperation(value = "加载挂载空间", notes = "接口备注：无", produces = "application/json")
    @PostMapping("subspaces")
    public Response loadWorkshopEnergyStuctsMenus(@RequestParam("spaces") String spaces, @RequestParam("type") String type) {

        List<EnergyStruc> treeDatas = energyStrucService.loadWorkshopEnergyStuctsMenus(type, spaces);

        return Response.ok(treeDatas);
    }

}
